package com.ruoyi.system.service.impl;

import java.util.List;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.system.domain.Bayonet;
import com.ruoyi.system.domain.Car;
import com.ruoyi.system.mapper.BayonetMapper;
import com.ruoyi.system.mapper.CarMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.AlarmMapper;
import com.ruoyi.system.domain.Alarm;
import com.ruoyi.system.service.IAlarmService;
import com.ruoyi.common.core.text.Convert;

/**
 * 报警信息Service业务层处理
 * 
 * @author zbb
 * @date 2023-02-13
 */
@Service
public class AlarmServiceImpl implements IAlarmService 
{
    @Autowired
    private AlarmMapper alarmMapper;
    @Autowired
    private CarMapper carMapper;
    @Autowired
    private BayonetMapper bayonetMapper;

    /**
     * 查询报警信息
     * 
     * @param alarmId 报警信息主键
     * @return 报警信息
     */
    @Override
    public Alarm selectAlarmByAlarmId(Long alarmId)
    {
        Alarm alarm = alarmMapper.selectAlarmByAlarmId(alarmId);
        String carNum = alarm.getCarNum();
        Car car=carMapper.selectCarByCarNum(carNum);
        String bayonetNum = alarm.getBayonetNum();
        Bayonet bayonet=bayonetMapper.selectBayonetByBayonetNum(bayonetNum);
        alarm.setCarNumType(car.getCarNumType());
        alarm.setXzqh(bayonet.getXzqh());
        alarm.setBayonetName(bayonet.getBayonetName());
        alarm.setLanesNum(bayonet.getLanesNum());
        return alarm;
    }

    /**
     * 查询报警信息列表
     * 
     * @param alarm 报警信息
     * @return 报警信息
     */
    @Override
    public List<Alarm> selectAlarmList(Alarm alarm)
    {
        List<Alarm> alarms = alarmMapper.selectAlarmList(alarm);
        for(int i=0;i<alarms.size();i++){
            String carNum = alarms.get(i).getCarNum();
            Car car=carMapper.selectCarByCarNum(carNum);
            String bayonetNum = alarms.get(i).getBayonetNum();
            Bayonet bayonet=bayonetMapper.selectBayonetByBayonetNum(bayonetNum);
            alarms.get(i).setCarNumType(car.getCarNumType());
            alarms.get(i).setXzqh(bayonet.getXzqh());
            alarms.get(i).setBayonetName(bayonet.getBayonetName());
            alarms.get(i).setLanesNum(bayonet.getLanesNum());
        }
        return alarms;
    }

    /**
     * 新增报警信息
     * 
     * @param alarm 报警信息
     * @return 结果
     */
    @Override
    public int insertAlarm(Alarm alarm)
    {
        alarm.setCreateTime(DateUtils.getNowDate());
        return alarmMapper.insertAlarm(alarm);
    }

    /**
     * 修改报警信息
     * 
     * @param alarm 报警信息
     * @return 结果
     */
    @Override
    public int updateAlarm(Alarm alarm)
    {
        alarm.setUpdateTime(DateUtils.getNowDate());
        return alarmMapper.updateAlarm(alarm);
    }

    /**
     * 批量删除报警信息
     * 
     * @param alarmIds 需要删除的报警信息主键
     * @return 结果
     */
    @Override
    public int deleteAlarmByAlarmIds(String alarmIds)
    {
        return alarmMapper.deleteAlarmByAlarmIds(Convert.toStrArray(alarmIds));
    }

    /**
     * 删除报警信息信息
     * 
     * @param alarmId 报警信息主键
     * @return 结果
     */
    @Override
    public int deleteAlarmByAlarmId(Long alarmId)
    {
        return alarmMapper.deleteAlarmByAlarmId(alarmId);
    }
}
